package com.example.demo.service;

<<<<<<< HEAD
import java.util.List;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
=======
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

>>>>>>> c827499e8bb31ca32bc4e6604c6b0e46aefc968e
import com.example.demo.bean.CmsArticle;
import com.example.demo.mapper.CmsArticleMapper;

@Service
public class CmsArticleService {
<<<<<<< HEAD
	
	@Autowired
	private CmsArticleMapper articleMapper;
	
	public void insert(CmsArticle article) {
		if(article.getId()!=null) {
			articleMapper.insert(article);
			System.out.println("有id"); 
		}else {
			String id = UUID.randomUUID().toString();
			article.setId(id);
			articleMapper.insert(article);
			System.out.println("无id");
		}

	}
	
	public int deleteById(String id) {
		return articleMapper.deleteByPrimaryKey(id);
	}
	
	public void saveOrUpdate(CmsArticle article) {
		if(article.getId()!=null) {
			articleMapper.updateByPrimaryKey(article);
			System.out.println("有id");
		}else {
			String id = UUID.randomUUID().toString();
			article.setId(id);
			articleMapper.updateByPrimaryKey(article);
			System.out.println("无id");
		}
	}
	
	public List<CmsArticle> findAll(){
		return articleMapper.selectAll();
	}
	
	public CmsArticle selectById(String id) {
		return articleMapper.selectByPrimaryKey(id);
	}
	
=======
	@Autowired		//跟Spring容器表明，需要你在运势是注入一个CmsCategoryMapper对象进来。
	CmsArticleMapper articleMapper;
	
	public List<CmsArticle> findAll(){
//		List<CmsArticle> list = categoryMapper.selectAll();
		List<CmsArticle> list = articleMapper.allArticleWithParent();
//		return categoryMapper.selectAll();
		if(list!=null) {
			return list;
		}
		return new ArrayList<CmsArticle>();
	}
>>>>>>> c827499e8bb31ca32bc4e6604c6b0e46aefc968e
}
